package com.sqgxy.cfg;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 对于springMVC的配置
 */
@Configuration
public class WebCfg implements WebMvcConfigurer {

    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                // 放开哪些端口、域名的访问权限
                .allowedOrigins(new String[]{"http://localhost:63342", "http://localhost:8000"})
                // 允许Cookie的携带
                .allowCredentials(true)
                .allowedHeaders("Content-Type","X-Requested-With","accept,Origin","Access-Control-Request-Method","Access-Control-Request-Headers", "Token")
                // 暴露哪些头部信息（因为跨域访问默认不能获取全部头部信息）.exposedHeaders("*")
                //.allowedMethods("GET", "POST","OPTIONS");
                .allowedMethods("*");
    }

}
